<?php
/**
 * ip库
 * @param string $ip
 * @param string $file
 * @return mixed
 */
/*function IP($ip = '', $file = 'UTFWry.dat') {
	$_ip = array ();
	if (isset ( $_ip [$ip] )) {
		return $_ip [$ip];
	} else {
		import ( "ORG.Net.IpLocation" );
		$iplocation = new IpLocation ( $file );
		$location = $iplocation->getlocation ( $ip );
		$_ip [$ip] = $location ['country'] . $location ['area'];
	}
	return $_ip [$ip];
}*/
/*function getNodeGroupName($id){
	if (empty ( $id )) {
		return '未分组';
	}
	if(isset( $_SESSION ['nodeGroupList'] )){
		return $_SESSION ['nodeGroupList'] [$id];
	}
	$Group = D ( "Group" );
	$list = $Group->getField ( 'id,title' );
	$_SESSION ['nodeGroupList'] = $list;
	$name = $list [$id];
	return $name;
}*/


/**
 +----------------------------------------------------------
 * 获取登录验证码 默认为4位数字
 +----------------------------------------------------------
 * @param string $fmode 文件名
 +----------------------------------------------------------
 * @return string
 +----------------------------------------------------------
 */
/*function build_verify($length = 4, $mode = 1) {
	return rand_string ( $length, $mode );
}*/

/*function sort_by($array, $keyname = null, $sortby = 'asc') {
	$myarray = $inarray = array ();
	# First store the keyvalues in a seperate array
	foreach ( $array as $i => $befree ) {
		$myarray [$i] = $array [$i] [$keyname];
	}
	# Sort the new array by
	switch ($sortby) {
		case 'asc' :
			# Sort an array and maintain index association...
			asort ( $myarray );
			break;
		case 'desc' :
		case 'arsort' :
			# Sort an array in reverse order and maintain index association
			arsort ( $myarray );
			break;
		case 'natcasesor' :
			# Sort an array using a case insensitive "natural order" algorithm
			natcasesort ( $myarray );
			break;
	}
	# Rebuild the old array
	foreach ( $myarray as $key => $befree ) {
		$inarray [] = $array [$key];
	}
	return $inarray;
}*/

//截取字符串的长度utf-8
/*function utf_substr($str, $start, $len) {
	if (strlen ( $str ) < $start) {
		return "";
	}
	$start = (ceil ( $start / 3 )) * 3;
	$str = substr($str,$start);
	
	for($i = 0; $i < $len; $i ++) {
		$temp_str = substr ( $str, 0, 1 );
		if (ord ( $temp_str ) > 127) {
			$i ++;
			if ($i < $len) {
				$new_str [] = substr ( $str, 0, 3 );
				$str = substr ( $str, 3 );
			}
		} else {
			$new_str [] = substr ( $str, 0, 1 );
			$str = substr ( $str, 1 );
		}
	}
	if (count ( $new_str ) > 1) {
		return implode($new_str);
	} else {
		return $new_str [0];
	}
}*/

/**
 * 计算文件的大小
 * @param $size 文件大小（字节）
 * @return string 以友好的方式显示文件大小
 */
function getRealSize($size){
	$kb = 1024; // Kilobyte
	$mb = 1024 * $kb; // Megabyte
	$gb = 1024 * $mb; // Gigabyte
	$tb = 1024 * $gb; // Terabyte
	if ($size < $kb) {
		return $size . " B";
	} else if ($size < $mb) {
		return round ( $size / $kb, 2 ) . " KB";
	} else if ($size < $gb) {
		return round ( $size / $mb, 2 ) . " MB";
	} else if ($size < $tb) {
		return round ( $size / $gb, 2 ) . " GB";
	} else {
		return round ( $size / $tb, 2 ) . " TB";
	}
}
/*
*	查询某个值是否在指定字段中出现
*	$str 要查询的字符串
*	$field 字段名
*	$array 要查询的数组
*/
/*function array_search_i($str,$field,$array){
    foreach($array as $key => $value) { 
        if($str == $value[$field]) return $key; 
    }
    return false;
}*/
/*
*	排序字段
*/
function orderField($field){
	if(empty($field))return '';
	$str = "orderField=\"$field\"";
	if($_REQUEST['orderField'] == $field){
		$str.=' class="'.$_REQUEST['orderDirection'].'"';
	}
	return $str;
}

/**
 * 获取二维数组某一key对应的所有值
 * @param  array $arr 数组
 * @param  string $field key
 * @param  bool $skipEmpty 是否跳过空值，默认true
 */
/*function get_array_value_list($arr, $field, $skipEmpty = true)
{
    $ret = array();
    foreach ($arr as $key => $val) {
        if (! $val) continue;
        if ($skipEmpty && empty($val[$field])) continue;
        $ret[] = $val[$field];
    }
    return $ret;
}*/